from machine import Pin
import utime

# 创建KEY对象
key_pins = [14, 27, 26, 25]
keys = [Pin(pin, Pin.IN, Pin.PULL_UP) for pin in key_pins]

# 创建LED对象
led_pins = [16, 17, 5, 18]
leds = [Pin(pin, Pin.OUT, value=0) for pin in led_pins]
leds_val = [0] * 4

# 外部中断回调函数
def key_handler(n):
    utime.sleep_ms(10)
    leds_val[n] = not leds_val[n]
    leds[n].value(leds_val[n])

if __name__ == "__main__":
    # 使用INT外部中断控制LED
    # 按键下降沿触发外部中断
    # [Pin].irq(handler, trigger)
    keys[0].irq(lambda n: key_handler(0), Pin.IRQ_FALLING)
        
    while True:
        pass

        
